/*
   Copyright (c) 2023 李伟国
   learner-platform is licensed under Mulan PSL v2.
   You can use this software according to the terms and conditions of the Mulan PSL v2. 
   You may obtain a copy of Mulan PSL v2 at:
               http://license.coscl.org.cn/MulanPSL2 
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
   See the Mulan PSL v2 for more details. 
*/

package cn.platform.controller;

import cn.platform.response.ResponseData;
import cn.platform.response.SuccessResponseData;
import cn.platform.entity.Message;
import cn.platform.service.ISystemSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SystemSocketController {

    @Autowired
    private ISystemSocketService systemSocketService;

    @SubscribeMapping("/hello")
    public ResponseData firstSay(){
        System.out.println("初次订阅");
        return new SuccessResponseData("订阅成功");
    }

    @SendTo("/topic/getResponse")
    public ResponseData say(Message message){
        return new SuccessResponseData("hahaha"+message.getName());
    }

    @MessageMapping("/hello")
    public void hello(String msg){
        System.out.println(msg);
    }

    @RequestMapping(value = "/haha", method = RequestMethod.GET)
    public ResponseData haha(){
        systemSocketService.send();
        return new SuccessResponseData("发布成功");
    }

}
